/*
 * Copyright Hundsun Technologies Inc. All Rights Reserved.
 */

package logging

import (
	"time"

	"github.com/sirupsen/logrus"
)

// TODO 后续logrus_log_impl.go删除掉
type logrusLogImpl struct {
	entry *logrus.Entry
	level LogLevel
}

//Printf ...
func (l *logrusLogImpl) Printf(format string, v ...interface{}) {
	l.entry.Printf(format, v...)
}

//Fatal ...
func (l *logrusLogImpl) Fatal(args ...interface{}) {
	l.entry.Fatal(args...)

}

//Fatalf ...
func (l *logrusLogImpl) Fatalf(format string, args ...interface{}) {
	l.entry.Fatalf(format, args...)
}

//Error ...
func (l *logrusLogImpl) Error(args ...interface{}) {
	l.entry.Error(args...)
}

//Errorf ...
func (l *logrusLogImpl) Errorf(format string, args ...interface{}) {
	l.entry.Errorf(format, args...)
}

//Warn ...
func (l *logrusLogImpl) Warn(args ...interface{}) {
	l.entry.Warn(args...)
}

//Warnf ...
func (l *logrusLogImpl) Warnf(format string, args ...interface{}) {
	l.entry.Warnf(format, args...)
}

//Info ...
func (l *logrusLogImpl) Info(args ...interface{}) {
	l.entry.Info(args...)
}

//Infof ...
func (l *logrusLogImpl) Infof(format string, args ...interface{}) {
	l.entry.Infof(format, args...)
}

//Debug ...
func (l *logrusLogImpl) Debug(args ...interface{}) {
	l.entry.Debug(args...)
}

//Debugf ...
func (l *logrusLogImpl) Debugf(format string, args ...interface{}) {
	l.entry.Debugf(format, args...)
}

//Trace ...
func (l *logrusLogImpl) Trace(args ...interface{}) {
	l.entry.Trace(args...)
}

//Tracef ...
func (l *logrusLogImpl) Tracef(format string, args ...interface{}) {
	l.entry.Tracef(format, args...)
}

//WithField ...
func (l *logrusLogImpl) WithField(fieldName string, fieldValue interface{}) Log {
	return &logrusLogImpl{
		entry: l.entry.WithField(fieldName, fieldValue),
		level: l.level,
	}
}

//WithCostField ...
func (l *logrusLogImpl) WithCostField(start time.Time) Log {
	return l.WithField(LogFieldCost, time.Since(start)/time.Millisecond)
}

//WithFields ...
func (l *logrusLogImpl) WithFields(fields map[string]interface{}) Log {
	return &logrusLogImpl{
		entry: l.entry.WithFields(fields),
		level: l.level,
	}
}

//IsDebugEnabled is debug level enabled
func (l *logrusLogImpl) IsDebugEnabled() bool {
	return l.entry.Logger.Level >= logrus.DebugLevel
}

//IsTraceEnabled is trace level enabled
func (l *logrusLogImpl) IsTraceEnabled() bool {
	return l.entry.Logger.Level == logrus.TraceLevel
}

// ElapsedTime 打印函数用时（毫秒）
// 用法: defer ElapsedTime("methodName", time.Now())
func (l *logrusLogImpl) ElapsedTime(methodName string, start time.Time) {
	l.entry.Trace("stats")
}

//GetLevel get log level
func (l *logrusLogImpl) GetLevel() LogLevel {
	return l.level
}
